﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.VisualStudio.Modeling;
using UofCASE.AgileProductLinerDSL;
using Microsoft.VisualStudio.Modeling.Validation;
using Microsoft.VisualStudio.Modeling.Diagrams;

namespace APLDTests {
    /// <summary>
    /// Summary description for CollapsingTest
    /// </summary>
    [TestClass]
    public class CollapsingTest {

        public CollapsingTest() {
        }

        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext {
            get {
                return testContextInstance;
            }
            set {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        [TestMethod]
        public void TestCollapsingClick() {
            ModelHelper model = ModelHelper.GetModel(true);

            //Assert pre conditions
            Assert.IsFalse(model.GetElement<TestPortShape>("testPortShape").IsCollapsed);
            Assert.IsTrue(model.GetElement<TestConnector>("testCon").IsVisible);
            Assert.IsTrue(model.GetElement<TestConnector>("testCon2").IsVisible);
            Assert.IsTrue(model.GetElement<TestShape>("testShape").IsVisible);
            Assert.IsFalse(model.GetElement<TestPortShape>("testPortShape2").IsCollapsed);
            Assert.IsTrue(model.GetElement<TestConnector>("testCon3").IsVisible);
            Assert.IsTrue(model.GetElement<FeaturePortShape>("featurePortShape").IsVisible);
            Assert.IsTrue(model.GetElement<FeaturePortShape>("featurePortShape2").IsVisible);
            Assert.IsTrue(model.GetElement<FeaturePortShape>("featurePortShape3").IsVisible);
            
            //click on testport of feature two (-> collapse)
            model.GetElement<TestPortShape>("testPortShape").ChangeCollapsing();
            //property
            Assert.IsTrue(model.GetElement<TestPortShape>("testPortShape").IsCollapsed);
            //visibilities
            Assert.IsFalse(model.GetElement<TestConnector>("testCon").IsVisible);
            Assert.IsFalse(model.GetElement<TestConnector>("testCon2").IsVisible);
            Assert.IsFalse(model.GetElement<FeaturePortShape>("featurePortShape").IsVisible);
            Assert.IsFalse(model.GetElement<TestShape>("testShape").IsVisible);
            Assert.IsTrue(model.GetElement<FeaturePortShape>("featurePortShape2").IsVisible);
            Assert.IsTrue(model.GetElement<TestShape>("testShape2").IsVisible);

            //click again on testport of feature two (->changecollapsing i.e. expand)
            model.GetElement<TestPortShape>("testPortShape").ChangeCollapsing();
            
            Assert.IsFalse(model.GetElement<TestPortShape>("testPortShape").IsCollapsed);

            Assert.IsTrue(model.GetElement<FeaturePortShape>("featurePortShape").IsVisible);
            Assert.IsTrue(model.GetElement<FeaturePortShape>("featurePortShape2").IsVisible);
            Assert.IsTrue(model.GetElement<TestConnector>("testCon").IsVisible);
            Assert.IsTrue(model.GetElement<TestConnector>("testCon2").IsVisible);
            Assert.IsTrue(model.GetElement<TestShape>("testShape").IsVisible);

            //now click on testPorts of feature 2 and 3 -> testShape2 should be hidden then
            model.GetElement<TestPortShape>("testPortShape2").ChangeCollapsing();
            Assert.IsTrue(model.GetElement<TestPortShape>("testPortShape2").IsCollapsed);
            
            Assert.IsFalse(model.GetElement<TestConnector>("testCon3").IsVisible);
            Assert.IsTrue(model.GetElement<FeaturePortShape>("featurePortShape2").IsVisible);
            Assert.IsTrue(model.GetElement<FeaturePortShape>("featurePortShape3").IsVisible);
            Assert.IsTrue(model.GetElement<TestShape>("testShape2").IsVisible);
            
            model.GetElement<TestPortShape>("testPortShape").ChangeCollapsing();
            Assert.IsTrue(model.GetElement<TestPortShape>("testPortShape").IsCollapsed);

            Assert.IsFalse(model.GetElement<FeaturePortShape>("featurePortShape2").IsVisible);
            Assert.IsFalse(model.GetElement<FeaturePortShape>("featurePortShape3").IsVisible);
            Assert.IsFalse(model.GetElement<TestShape>("testShape2").IsVisible);
        }

        [TestMethod]
        public void TestFeaturePortMouseHover() {
            ModelHelper model = ModelHelper.GetModel(true);
            
            model.GetElement<TestPortShape>("testPortShape").ChangeCollapsing();
            Assert.IsFalse(model.GetElement<TestConnector>("testCon2").IsVisible);
            Assert.IsTrue(model.GetElement<FeaturePortShape>("featurePortShape2").IsVisible);

            model.GetElement<FeaturePortShape>("featurePortShape2").ShowPreview();
            Assert.IsTrue(model.GetElement<TestConnector>("testCon2").IsVisible);

            model.GetElement<FeaturePortShape>("featurePortShape2").HidePreview();
            Assert.IsFalse(model.GetElement<TestConnector>("testCon2").IsVisible);
        }


        [TestMethod]
        public void TestShapeMouseHover() {
            ModelHelper model = ModelHelper.GetModel(true);

            model.GetElement<TestPortShape>("testPortShape2").ChangeCollapsing();
            Assert.IsTrue(model.GetElement<TestConnector>("testCon2").IsVisible);
            Assert.IsFalse(model.GetElement<TestConnector>("testCon3").IsVisible);

            
            model.GetElement<TestShape>("testShape2").ShowPreview();
            Assert.IsTrue(model.GetElement<TestConnector>("testCon2").IsVisible);
            Assert.IsTrue(model.GetElement<TestConnector>("testCon3").IsVisible);
            
            model.GetElement<TestShape>("testShape2").HidePreview();
            Assert.IsTrue(model.GetElement<TestConnector>("testCon2").IsVisible);
            Assert.IsFalse(model.GetElement<TestConnector>("testCon3").IsVisible);
        }
    }
}
